package com.captain.special.二叉树.简单;

import com.captain.leetcode.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/5/7 16:35
 */
public class 二叉树的坡度563 {
    int ans = 0;

    public int findTilt(TreeNode root) {
        recur(root);
        return ans;
    }

    public int recur(TreeNode node) {
        if (node == null) {
            return 0;
        }
        int l = recur(node.left);
        int r = recur(node.right);
        int curVal = node.val;
        ans += Math.abs(l - r);
        return l + r + curVal;
    }
}
